package com.zyy.game.tianlong.vo;

import com.zyy.game.tianlong.network.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 交互bean
 * @author relufi
 * @date 2019/8/12 0012
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVo<T> {
    private int code;
    private T data;

    private static final ResultVo SUCCESS = new ResultVo<>();

    public static <S> ResultVo<S> success(S t) {
        ResultVo<S> resultVo = new ResultVo<>();
        resultVo.setData(t);
        return resultVo;
    }
    public static ResultVo success() {
        return SUCCESS;
    }
    public static <S> ResultVo<S> error(int code, S t) {
        ResultVo<S> resultVo = new ResultVo<>();
        resultVo.setData(t);
        resultVo.setCode(code);
        return resultVo;
    }
    public static ResultVo error(int code) {
        ResultVo<Object> resultVo = new ResultVo<>();
        resultVo.setCode(code);
        return resultVo;
    }
    public static ResultVo error(ServiceException e) {
        return new ResultVo<>(e.getCode(),e.getMessage());
    }
}
